import 'package:get/get.dart';

import '../key_value_model.dart';

class KeyValueProvider extends GetConnect {
  @override
  void onInit() {
    httpClient.defaultDecoder = (map) {
      if (map is Map<String, dynamic>) return KeyValue.fromJson(map);
      if (map is List)
        return map.map((item) => KeyValue.fromJson(item)).toList();
    };
    httpClient.baseUrl = 'YOUR-API-URL';
  }

  Future<KeyValue?> getKeyValue(int id) async {
    final response = await get('keyvalue/$id');
    return response.body;
  }

  Future<Response<KeyValue>> postKeyValue(KeyValue keyvalue) async =>
      await post('keyvalue', keyvalue);
  Future<Response> deleteKeyValue(int id) async => await delete('keyvalue/$id');
}
